﻿using CRM.Infrastructure.EFCore.Mysql;
using CRM.Infrastructure.Tools;
using CRM.Service.Interface;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace CRM.Api.Admin.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class BaseController : ControllerBase
    {
        protected readonly I_Login_Service _Login_Service;

        public BaseController(I_Login_Service login_Service)
        {
            _Login_Service = login_Service;
        }


        protected async Task<SysUser> Get_Curr_User()
        {
            string code = this.User.Claims.ToList().First(o => o.Type == System.Security.Claims.ClaimTypes.Name).Value;
            var user = await _Login_Service.Get_User_By_LastCode(code, Config.GetIp());
            if (user == null)
            {
                throw new Exception("请重新登录");
            }
            return user;

        }
    }
}
